package com.example.jinzproduct.server.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.commons.entity.KnowledgePointsDO;
import com.example.commons.entity.Tree;
import com.example.commons.utils.BuildTree;
import com.example.jinzproduct.dao.KnowledgePointsDao;
import com.example.jinzproduct.server.KnowledgePointsService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * <pre>
 * 知识点
 * </pre>
 * <small> 2020-02-24 21:00:12 | lance</small>
 */
@Service
public class KnowledgePointsServiceImpl extends ServiceImpl<KnowledgePointsDao, KnowledgePointsDO> implements KnowledgePointsService {


    @Override
    public Tree<KnowledgePointsDO> getTree() {
        List<Tree<KnowledgePointsDO>> trees = new ArrayList<Tree<KnowledgePointsDO>>();
        List<KnowledgePointsDO> sysDepts = baseMapper.selectList(null);
        for (KnowledgePointsDO sysDept : sysDepts) {
            Tree<KnowledgePointsDO> tree = new Tree<KnowledgePointsDO>();
            tree.setLevel(sysDept.getLevel());
            tree.setId(sysDept.getId().toString());
            tree.setParentId(sysDept.getPid().toString());
            tree.setText(sysDept.getName());
            Map<String, Object> state = new HashMap<>(16);
            state.put("opened", true);
            tree.setState(state);
            trees.add(tree);
        }
        // 默认顶级菜单为０，根据数据库实际情况调整
        Tree<KnowledgePointsDO> t = BuildTree.build(trees);
        return t;
    }

    @Override
    public List<Map<Object,Object>> selByAll(){
        return baseMapper.selByAll();
    }

    @Override
    public List<KnowledgePointsDO> selectListBy(Map map) {
        return baseMapper.selectListBy(map);
    }

    @Override
    public List<KnowledgePointsDO> selectListAll() {
        return baseMapper.selectListAll();
    }

    @Override
    public List<KnowledgePointsDO> selByProidGrade(Map map){
        return baseMapper.selByProidGrade(map);
    }
}
